package com.health.db.dao.sm.impl;

import java.util.List;

import com.health.db.dao.ServiceInterface;
import com.health.db.dao.sm.IAdvertisementListDao;
import com.health.db.mapper.AdvertisementListMapper;
import com.health.db.model.AdvertisementListExample;
import com.health.db.model.AdvertisementListTemp;
import com.health.redis.RedisConstants;

public class  AdvertisementListDaoImpl  extends ServiceInterface implements IAdvertisementListDao
{
	
	AdvertisementListMapper advertisementListMapper;
	String  selectByPositionId=":positionId:";
	String  Offset=":OF:";
	String  PageSize=":PS:";
	String  selectByTop=":selectByTop:";
 
	/**
	 * @return the advertisementListMapper
	 */
	public AdvertisementListMapper getAdvertisementListMapper() {
		return advertisementListMapper;
	}

	/**
	 * @param advertisementListMapper the advertisementListMapper to set
	 */
	public void setAdvertisementListMapper(
			AdvertisementListMapper advertisementListMapper) {
		this.advertisementListMapper = advertisementListMapper;
	}

	/**
	 * @methodOrder s1
	 * example
	 * {
     *    positionid 位置id
     *    offset     偏移量
     *    pageSize   数量 
     * }
	 */
	@Override
	public List<AdvertisementListTemp> selectSimple(AdvertisementListExample example ) {
		// TODO Auto-generated method stub
		getRedisOperatiorLogic();
		String key=RedisConstants.AdvertisementListMapper+selectByPositionId+example.getPositionid()
				+Offset+example.getOffset()+PageSize+example.getPageSize();
		Object object=null;
		List<AdvertisementListTemp> list=null;
		if(redisOperatiorLogic.isJedisIsConnected())
		{
			object = redisOperatiorLogic.readObject(key, getOrderRedisGroupNo("1"));
		}
		if(null!=object){
			
			if (!object.equals("")) {
				list =  (List) object;
			}
		}
		else
		{
			list=advertisementListMapper.selectSimple(example);
			if(redisOperatiorLogic.isJedisIsConnected())
			{
			redisOperatiorLogic.setEx(key, list, getOrderRedisGroupNo("1"));
			}
		}
		return list;
	}
	
	/**
	 * 无参数
	 */
	@Override
	public AdvertisementListTemp selectByTop() {
		
		// TODO Auto-generated method stub
		getRedisOperatiorLogic();
		String key=RedisConstants.AdvertisementListMapper+selectByTop;
		Object object=null;
		AdvertisementListTemp temp =null;
		if(redisOperatiorLogic.isJedisIsConnected())
		{
			object = redisOperatiorLogic.readObject(key, getOrderRedisGroupNo("1"));
		}
		if(null!=object){
			
			if (!object.equals("")) {
				temp =  (AdvertisementListTemp) object;
			}
		}
		else
		{
			temp =  advertisementListMapper.selectByTop();
			if(redisOperatiorLogic.isJedisIsConnected())
			{
			redisOperatiorLogic.setEx(key, temp, getOrderRedisGroupNo("1"));
			}
		}
		return temp;
		
	}
	
	private void deleteFuzzyObject(){
		
	}

	@Override
	public int updateReadAmount(Long advertisementid) {
		// TODO Auto-generated method stub
		return advertisementListMapper.updateReadAmount(advertisementid);
	}

}
